package com.onejson.ojmall.controller;


import com.onejson.ojmall.common.domain.PageResult;
import com.onejson.ojmall.common.apiencrypt.domain.ValidateList;
import com.onejson.ojmall.common.domain.ResponseDTO;
import com.onejson.ojmall.model.form.SRoleMenuBatchForm;
import com.onejson.ojmall.model.form.SRoleMenuForm;
import com.onejson.ojmall.model.form.SRoleMenuQueryForm;
import com.onejson.ojmall.model.vo.SRoleMenuVO;
import com.onejson.ojmall.service.SRoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 角色-菜单控制器
 *
 * @author wxx
 */
@Slf4j
@RestController
@Tag(name = "角色-菜单")
public class SRoleMenuController {


    //【角色-菜单】Service层

    @Resource
    private SRoleMenuService sRoleMenuService;


    @Operation(summary = "【角色-菜单】 - 查询")
    @PostMapping("/zichan/sRoleMenu/queryPage")
    public ResponseDTO<PageResult<SRoleMenuVO>> querySRoleMenu(@RequestBody @Valid SRoleMenuQueryForm queryForm) {
        return ResponseDTO.ok(sRoleMenuService.getList(queryForm));
    }

    @Operation(summary = " 【角色-菜单】 - 详情")
    @GetMapping("/zichan/sRoleMenu//{detailId}")
    public ResponseDTO<SRoleMenuVO> getInfo(@PathVariable("detailId") String detailId) {
        return ResponseDTO.ok(sRoleMenuService.queryById(detailId));
    }

    @Operation(summary = " 【角色-菜单】 - 添加")
    @PostMapping("/zichan/sRoleMenu/add")
    public ResponseDTO<String> addSRoleMenu(@RequestBody @Valid SRoleMenuForm addForm) {
        return sRoleMenuService.addSRoleMenu(addForm);
    }

    @Operation(summary = "【角色-菜单】 - 更新")
    @PostMapping("/zichan/sRoleMenu/update")
    public ResponseDTO<String> updateSRoleMenu(@RequestBody @Valid SRoleMenuForm updateForm) {
        return sRoleMenuService.updateSRoleMenu(updateForm);
    }

    @Operation(summary = "【角色-菜单】 - 批量更新")
    @PostMapping("/zichan/sRoleMenu/batchUpdate")
    public ResponseDTO<String> batchUpdateSRoleMenu(@RequestBody @Valid SRoleMenuBatchForm sRoleMenuBatchForm) {
        return sRoleMenuService.batchUpdateSRoleMenu(sRoleMenuBatchForm);
    }

    @Operation(summary = "【角色-菜单】 - 批量删除")
    @PostMapping("/zichan/sRoleMenu/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<String> idList) {
        return sRoleMenuService.batchDelete(idList);
    }

    @Operation(summary = "【角色-菜单】 - 单个删除")
    @GetMapping("/zichan/SRoleMenu/delete/{id}")
    public ResponseDTO<String> batchDelete(@PathVariable String id) {
        return sRoleMenuService.delete(id);
    }

}

